package com.demo.writer_;

import com.demo.reader_.FileReader01;
import org.apache.log4j.Logger;
import org.junit.Test;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

/**
 * @author gy
 * @date 2022/4/4
 */
public class FileWriter01 {

    private static final Logger logger = Logger.getLogger(FileWriter01.class);


    @Test
    public void m2() {
        String filePath = "f:\\20220403\\fileWriter.txt";

        FileWriter fileWriter = null;
        int readLength = 0;
        char[] buf = {'a','b','c'};
        try {
            logger.info("创建 字符 输出流对象--fileWriter");
            fileWriter = new FileWriter(filePath);
            fileWriter.write('H');
            fileWriter.write(buf);
            fileWriter.write("输出流对象");
            fileWriter.write("输出流对象".toCharArray(),0,3);

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (fileWriter != null) {
                    fileWriter.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

}
